// import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/theme/theme-green/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
// import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import routes from './routes'
import axios from "axios";
// import Mock from './mock'
// Mock.bootstrap();
// import 'font-awesome/css/font-awesome.min.css'
Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)
//NProgress.configure({ showSpinner: false });

const router = new VueRouter({
  routes
})
//请求拦截器
axios.interceptors.request.use(config => {
  if (window.localStorage.getItem('token')&&config.url.indexOf('login')==-1) {
    //判断token是否存在
    config.headers.token = JSON.parse(localStorage.getItem('token')).token;  //将token设置成请求头
  }
  return config;
})

//路由拦截器
router.beforeEach((to, from, next) => {
  if (to.path=='/login'){
    next()
  }
  else if (localStorage.getItem('token')!=null) {
    next();
  }
  else {
    next({path:'/login'})
  }
})

const nowVue = new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  beforeCreate(){
    Vue.prototype.$bus=this;
  },
  store,
  //components: { App }
  render: h => h(App)
}).$mount('#app')

